Skip to content

Ignore inline notes during Markdown reference parsing#1713

Open
skatkov wants to merge 2 commits into
ruby:masterfrom
skatkov:markdown-note-state-reset
Open

Ignore inline notes during Markdown reference parsing#1713
skatkov wants to merge 2 commits into
ruby:masterfrom
skatkov:markdown-note-state-reset

Conversation

@skatkov
Copy link
Copy Markdown

@skatkov skatkov commented May 14, 2026

Inline notes inside reference labels can be parsed during the reference-gathering pass, before footnote ordering is initialized.

RDoc::Markdown.parse("[foo ^[note]]: /url\n")

This will crash a Markdown parser with a NoMethodError.

This change treats inline-note creation as a no-op until note ordering exists.

Inline notes inside reference labels can run during the reference-gathering pass. Reset note state for each parse and reject inline notes before note ordering starts so reused parser instances do not accept stale footnote data.
Copilot AI review requested due to automatic review settings May 14, 2026 15:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Resets @footnotes and @note_order to nil at the start of each parse call, and makes the InlineNote rule raise a ParseError when invoked before notes are initialized (e.g., during the references-gathering pass on a reused parser instance).

Changes:

  • Reset @footnotes and @note_order to nil at the start of parse to prevent leakage across reused parser instances.
  • Update the InlineNote PEG rule action to raise ParseError, 'invalid inline note' when @note_order is nil.
  • Add a regression test exercising an inline note inside a reference label after a prior parse.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
lib/rdoc/markdown.kpeg Source grammar: clear note state on parse and guard InlineNote action.
lib/rdoc/markdown.rb Generated parser mirroring the kpeg changes (state reset + guard + Rules entry).
test/rdoc/rdoc_markdown_test.rb New test validating the ParseError is raised on inline notes within reference labels after reuse.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/rdoc/markdown.kpeg Outdated
Comment thread lib/rdoc/markdown.kpeg Outdated
Inline notes can be parsed while Markdown references are being collected, before footnote ordering has been initialized. Treat that early pass as a no-op so malformed reference labels do not crash the parser.
@skatkov skatkov changed the title Reset Markdown note state between parses Ignore inline notes during Markdown reference parsing May 14, 2026
@skatkov skatkov requested a review from tompng May 14, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants